package com.wbs.batis.rest;


import org.apache.ibatis.binding.MapperMethod;
import org.mybatis.spring.SqlSessionTemplate;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;


public class RestMapperProxy implements InvocationHandler, Serializable {

    Class<?> mapperInterface;

    SqlSessionTemplate sqlSessionTemplate;


    public RestMapperProxy(Class<?> mapperInterface, SqlSessionTemplate sqlSessionTemplate) {
        this.mapperInterface = mapperInterface;
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {
        MapperMethod mapperMethod = new MapperMethod(mapperInterface, method, sqlSessionTemplate.getConfiguration());
        return mapperMethod.execute(sqlSessionTemplate, args);
    }

}
